#include "ButtonGroupCell.h"
#include <QHBoxLayout>
#include <QStyle>

ButtonGroupCell::ButtonGroupCell(QVariant param, QWidget *parent)
    : CellBase (parent){
    _param = param;

    QHBoxLayout *boxLayout = new QHBoxLayout(this);
    setLayout(boxLayout);

    _buttonShell.shell(this);
    _buttonShell.setSelectable(false);
    auto list = param.toList();
    for (auto iter=list.begin(); iter!=list.end(); iter++) {
        QVariantMap map = iter->toMap();
        auto title = map.value("title").toString();
        auto name = map.value("name").toString();
        _buttons << _buttonShell.add<QPushButton>(name,title);
    }
    connect(&_buttonShell,&ButtonGroup::sigClicked,this,&ButtonGroupCell::onClicked);
}
ButtonGroupCell::~ButtonGroupCell(){
}

void ButtonGroupCell::updateData(const QVariant &data){
    Q_UNUSED(data);
}
void ButtonGroupCell::setData(const QVariant &data){
    Q_UNUSED(data);
}
CellBase* ButtonGroupCell::ctor(QWidget *parent){
    return new ButtonGroupCell(_param,parent);
}

void ButtonGroupCell::setActived(bool actived){
    CellBase::setActived(actived);
}

void ButtonGroupCell::polish(){
    style()->polish(this);
    foreach(auto *button, _buttons){
        style()->polish(button);
    }
}
void ButtonGroupCell::onClicked(QString name){
    emit sigEvent(name,"clicked");
}
